<?php

// +----------------------------------------------------------------------
// | laravelvip 乐融沃B2B2C商城系统
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.laravelvip.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// +----------------------------------------------------------------------
// | 版权所有 2015-2027 云南乐融沃网络科技有限公司，并保留所有权利。
// | 网站地址: http://www.laravelvip.com
// +----------------------------------------------------------------------
// | 这不是一个自由软件！禁止拷贝本软件副本，否则将追究其法律责任！
// | 如需使用，请移步官网购买正版授权。
// +----------------------------------------------------------------------
// | Author: 雲溪荏苒 <290648237@qq.com>
// | Date:2018-08-10
// | Description:
// +----------------------------------------------------------------------

namespace App\Repositories;


use App\Models\MessageTemplate;
use Illuminate\Support\Facades\DB;

class MessageTemplateRepository
{
    use BaseRepository;

    protected $model;


    public function __construct()
    {
        $this->model = new MessageTemplate();
    }

    /**
     * 获取模版信息
     *
     * @param string $templateCode 模版标识
     * @param string $msgType 模版消息类型
     * @return mixed
     */
    public function getTemplateConfig($templateCode, $msgType)
    {
        $info = MessageTemplate::where([['code', $templateCode]])
            ->select(DB::raw("{$msgType}_open as is_open,{$msgType}_content as content,{$msgType}_spec as spec, name,code,aliyu_code"))
            ->first();
        if (empty($info)) {
            throw new \Exception('消息模版不存在');
        }

        return $info->toArray();
    }
}
